<template>
  <div class="newIm">
    <div class="imConatiner">
      <div class="mainBody">
        <imHeader></imHeader>
        <div class="contentBase">
          <div class="leftAside">
            <div class="search_Div">
              <i class="el-icon-search"></i>
              <input placeholder="联系人" @focus="searchFlag = true" @blur="searchFlag = false" v-model="searchText" type="text" />
            </div>
            <div class="frendList">
              <el-tabs v-model="activeName" @tab-click="handleClick">
                <el-tab-pane label="消息" name="first">
                  <conversation-list />
                </el-tab-pane>
                <el-tab-pane label="联系人" name="second">
                  <followLists v-if="activeName == 'second'" :search="searchText" />
                </el-tab-pane>
              </el-tabs>
            </div>
          </div>
          <div class="conterContainer">
            <!-- 99999 -->
            <msgHeader v-if="conversationList.length > 0" v-show="headerShow" :baseMsg="baseMsg"></msgHeader>
            <current-conversation :text="text" />
          </div>
          <rightInfo @selectText="send_text" :baseMsg="baseMsg"></rightInfo>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
import imHeader from "@/components/im_new/newIm/im_header.vue";
import currentConversation from "./conversation/current-conversationnew";
import followLists from "./conversation/follow-lists";
import conversationList from "./conversation/conversation-list";
import rightInfo from "./newIm/right_info.vue";
import msgHeader from "./newIm/msgHeader.vue";
export default {
  components: {
    imHeader,
    currentConversation,
    rightInfo,
    followLists,
    conversationList,
    msgHeader,
  },
  computed: {
    ...mapState({
      conversationList: (state) => state.conversation.conversationList,
      currentConversation: (state) => state.conversation.currentConversation,
      headerShow: (state) => state.headerShow,
    }),
    showCurrentConversation() {
      return !!this.currentConversation.conversationID;
    },
  },
  data() {
    return {
      activeName: "first",
      activeName2: "first",
      text: "",
      search_2: "",
      UserId: null,
      searchText: "",
      baseMsg: {},
      searchFlag: false, // 好友搜索输入框是否选中
    };
  },
  watch: {
    activeName(val) {
      if (val == "first") {
        this.searchText = "";
      }
    },
  },
  created() {
    if (!this.showCurrentConversation || this.conversationList.length == 0) {
      this.$store.commit("set_chat_userinfo", {});
    }
    this.endSearch(); // 绑定回车事件
  },
  mounted() {
    this.$store.dispatch("getMobileWebSite");
    if (this.$route.query.id) {
      this.$store.dispatch("checkoutConversation", this.$route.query.id);
      window.history.replaceState("", "", this.$route.path);
    }
  },
  methods: {
    send_text(text) {
      this.text = "";
      this.text = text;
      console.log("send", this.text);
    },
    handleClick(tab, event) {
      console.log(event);
    },
    endSearch() {
      document.onkeydown = (e) => {
        //13表示回车键，baseURI是当前页面的地址，为了更严谨，也可以加别的，可以打印e看一下
        if (e.keyCode === 13 && this.searchFlag) {
          //回车后执行搜索方法
          this.handleSearch();
        }
      };
    },
    handleSearch() {
      // 搜索
      this.activeName = "second";
      this.$bus.$emit("getFollow");
    },
  },
};
</script>

<style lang="less" scoped>
.newIm {
  /deep/ .el-tabs__header {
    margin-bottom: 0 !important;
  }
  /deep/ .el-tabs__nav-scroll {
    padding: 0 20px;
  }
  /deep/ .chatObj #tab-first {
    height: 65px;
    line-height: 65px;
  }
  /deep/ .chatObj .el-tabs__nav-wrap {
    background-color: rgb(242, 244, 245);
  }
  /deep/ .el-tabs__nav-scroll {
    padding: 0 20px;
  }
  /deep/ .el-tabs__item {
    color: rgb(87, 89, 106);
  }
  /deep/ .el-tabs__item.is-active {
    color: #000;
    font-weight: bold;
  }
}
.imConatiner {
  width: 100%;
  // 超级好用的技巧  calc(100vh - 60px) 动态的计算出一个高度
  height: calc(100vh - 60px);
  // flex: 1;
  background-color: rgb(74, 90, 108);
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  .code1 {
    position: absolute;
    width: 115px;
    height: 115px;
    right: 20px;
    bottom: 100px;
    background-color: rebeccapurple;
  }
  .mainBody {
    width: 1500px;
    height: 750px;
    border-radius: 8px;
    overflow: hidden;
    background-color: #fff;
    box-shadow: 0 0 20px rgb(54, 68, 84);
    display: flex;
    flex-direction: column;
    position: relative;
    .contentBase {
      flex: 1;
      background-color: skyblue;
      display: flex;

      .leftAside {
        width: 300px;
        background-color: #fff;
        height: 100%;
        padding-top: 10px;
        border-right: 2px solid rgb(215, 223, 219);
        .search_Div {
          width: 88%;
          height: 40px;
          background-color: red;
          margin: 0 auto;
          display: flex;
          align-items: center;
          background-color: rgb(244, 246, 248);
          border-radius: 25px;
          padding-left: 15px;
          i {
            color: rgb(213, 221, 218);
            font-size: 25px;
          }
          input {
            height: 100%;
            background: none;
            padding-left: 15px;
            &::placeholder {
              color: rgb(108, 108, 109);
            }
          }
        }
      }

      .conterContainer {
        width: 850px;
        height: 100%;
        background-color: #fff;
        position: relative;
        padding-top: 65px;
        border-right: 2px solid rgb(215, 223, 219);
        .msgHeader {
          height: 65px;
          width: 100%;
          background-color: skyblue;
          display: flex;
          justify-content: space-between;
          align-items: center;
          font-size: 20px;
          background-color: rgb(242, 244, 245);
          border-bottom: 2px solid rgb(208, 216, 224);
          box-shadow: 0 0 5px #ccc;
          padding: 0 15px;
          position: absolute;
          top: 0;
          > div:nth-child(1) {
            display: flex;
            align-items: center;
            > img {
              width: 50px;
              height: 50px;
              border-radius: 5px;
            }
            span {
              color: rgb(20, 23, 56);
              margin-left: 10px;
            }
          }
          > div:nth-child(2) {
            color: rgb(189, 201, 210);
            i {
              margin: 0 8px;
              font-size: 22px;
              cursor: pointer;
            }
          }
        }
      }
    }
  }
}
.code1 {
  position: absolute;
  right: 45px !important;
  bottom: 350px !important;
  width: 50px;
  height: 50px;
  .titles {
    margin-top: 10px;
    p {
      color: rgb(83, 130, 186);
      font-weight: bold;
      font-size: 16px;
    }
  }
}

.codetwo {
  position: absolute;
  right: 45px !important;
  bottom: 160px !important;
  width: 115px;
  height: 115px;
  > img {
    width: 115px !important;
    height: 115px !important;
  }
  .titles {
    margin-top: 10px;
    p {
      color: rgb(83, 130, 186) !important;
      font-weight: bold !important;
      font-size: 16px;
    }
  }
}

.current-conversation-item {
  background: #f2f5fa;
}
</style>
